﻿using Framework.Core.Cache;
using Framework.Core.Recorder;
using Rhino.Mocks;
using Xunit;

namespace Framework.Tests.Core.Recorder
{
    public class StateLessCallKeyBuilderTest
    {
        private readonly CallKeyBuilder target;
        private readonly MockRepository mockRepository = new MockRepository();
        private readonly ICacheKeyBuilder cacheKeyBuilderMock;

        public StateLessCallKeyBuilderTest()
        {
            cacheKeyBuilderMock = mockRepository.StrictMock<ICacheKeyBuilder>();
            target = new CallKeyBuilder(cacheKeyBuilderMock);
        }

        [Fact]
        public void Should_just_return_key_for_state_less_call()
        {
            BuildTimes(10);
        }

        private void BuildTimes(int counter)
        {
            const string key = "toto";

            for (var i = 0; i < counter; i++)
            {
                cacheKeyBuilderMock.Expect(x => x.Build(null)).Return(key);
                mockRepository.ReplayAll();
                var actual = target.Build(null);

                Assert.Equal(key, actual);
            }
            mockRepository.VerifyAll();
        }
    }
}